//    Copyright (C) Kherty.  All rights reserved.
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System;

namespace OpenLS.UI
{
    static class Enumerable
    {
        public static double Sum<TSource>(IEnumerable<TSource> source, Func<TSource, double> selector)
        {
            Contract.Requires(source != null);
            double result = 0;
            foreach (var tSource in source)
            {
                result += selector(tSource);
            }
            return result;
        }
        internal delegate TResult Func<T, TResult>(T arg);
        internal static int Count<T>(IEnumerable<T> source, Predicate<T> predicate)
        {
            Contract.Requires(source != null);
            int result = 0;
            foreach (var enumerable in source)
            {
                if (predicate(enumerable))
                    result++;
            }
            return result;
        }
 

    }
}